package com.cjq.es.service.impl;

import com.cjq.common.domain.request.InviteQueryReq;
import com.cjq.common.domain.response.InviteQueryRes;
import com.cjq.common.result.PageResult;
import com.cjq.common.result.Result;
import com.cjq.common.utils.StringUtils;
import com.cjq.es.service.EsService;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EsServiceImpl implements EsService {

    @Override
    public Result<PageResult<InviteQueryRes>> list(InviteQueryReq inviteQueryReq) {
        long total = 0;
        ArrayList<InviteQueryRes> inviteQueryRes = new ArrayList<>();
        //创建 条件查询
        SearchRequest searchRequest = new SearchRequest();
        //创建 条件查询构造器
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //创建 多条件拼接对象
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        //开始 条件拼接
        if (StringUtils.isNotBlank(inviteQueryReq.getPosName())){
            boolQueryBuilder.must(QueryBuilders.matchQuery("posName",inviteQueryReq.getPosName()));
        }

        return PageResult.toResult(total,inviteQueryRes);
    }
}
